package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Update {
    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://127.0.0.1:3306/linyujie?useUnicode=true&amp;characterEncoding=utf-8";
        String username = "root";
        String password = "123456";
        Connection con = null;
        PreparedStatement p = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection(url,username,password);
            String sql = "update user set username=?,password=? where id=? ";
            p = con.prepareStatement(sql);
            p.setString(1,"yujie");
            p.setString(2,"123456");
            p.setInt(3,2);
            int a = p.executeUpdate();
            if(a == 1){
                System.out.println("成功");
            }else{
                System.out.println("失败");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        con.close();
        p.close();
    }
}
